﻿/**
 * 
 * Copyright 2009, 2010 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using moose.irc;

namespace mooseirc
{
    /// <summary>
    /// IRC Session
    /// </summary>
    internal class Session : object
    {
        #region [Local Attributes]

        /// <summary>
        /// IRC Session
        /// </summary>
        private IrcSession m_session;

        /// <summary>
        /// Reference to the status form UI
        /// </summary>
        private StatusForm m_status_form;

        
        
        #endregion

        #region [Delegates]
        
        /// <summary>
        /// Echos status message to status form
        /// </summary>
        private EchoFormHandler EchoStatusMessage;
        
        #endregion

        #region [Construction]

        /// <summary>
        /// Initialize Session
        /// </summary>
        internal Session(MainForm parent_form)
            : base()
        {
        	
        	init_delegates();
        	
            m_session = new IrcSession();
            m_session.Event += onIrcEvent;

            m_status_form = new StatusForm(m_session);
            m_status_form.MdiParent = parent_form;
            m_status_form.Show();

            //TODO: Remove this
            m_session.Settings_Session[IrcSessionSettings.NICKNAME] = "mikeyj";
            m_session.Settings_Session[IrcSessionSettings.REAL_NAME] = "mike";
            m_session.Settings_Session[IrcSessionSettings.USER_NAME] = "mike";

            return;
        }

        /// <summary>
        /// Sets up all delegates
        /// </summary>
        private void init_delegates()
        {
            EchoStatusMessage += new EchoFormHandler(Utility.EchoStatusMessage_StatusForm);
            return;
        }

        #endregion

        #region [Event Handlers]

        /// <summary>
        /// Fires on IRC Event
        /// </summary>
        private void onIrcEvent(IrcSession session, IrcEvent irc_event)
        {
            switch (irc_event.EventType)
            {
                case IrcEventTypes.MessageStatus:
	      			Program.m_frmMain.BeginInvoke(EchoStatusMessage,
	                    new object[] { 
	                    m_status_form, 
	                    (string)irc_event.Arguments[IrcEventArgumentType.Message].Value
            		});
                    break;
                case IrcEventTypes.NoticeMessage:
                    break;
                case IrcEventTypes.PrivateMessage:
                    break;
                case IrcEventTypes.ServerConnected:
                    break;
                case IrcEventTypes.ServerDisconnected:
                    break;
                case IrcEventTypes.ServerRegistered:
                    break;
                case IrcEventTypes.ChannelJoined:
                    break;
                case IrcEventTypes.ChannelJoinedSelf:
                    break;
                case IrcEventTypes.ChannelKicked:
                    break;
                case IrcEventTypes.ChannelKickedSelf:
                    break;
                case IrcEventTypes.ChannelModeChange:
                    break;
                case IrcEventTypes.ChannelParted:
                    break;
                case IrcEventTypes.ChannelPartedSelf:
                    break;
                case IrcEventTypes.ChannelTopicChange:
                    break;
                case IrcEventTypes.UserNickChange:
                    break;
                case IrcEventTypes.UserNickChangeSelf:
                    break;
                case IrcEventTypes.UserQuit:
                    break;
                case IrcEventTypes.UserQuitSelf:
                    break;
            };

            return;
        }

        #endregion

    }
}
